package org.etom.impl.ui.views;

import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.part.ViewPart;

/**
 * An abstract resource view.
 */
public abstract class AbstractResourcesView extends ViewPart {

  protected Composite parent;
  protected TreeViewer treeViewer;
  protected MenuManager menuManager;

  /*===[ViewPart methods][Start]====*/
  @Override
  public void createPartControl(Composite parent) {
    this.parent = parent;
    createTreeViewer();
    createContextMenu();
  }

  /**
   * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
   */
  @Override
  public void setFocus() {
  }
  /*===[ViewPart methods][End]====*/

  /*
   * The method creates the tree viewer.
   */
  private void createTreeViewer() {
    this.treeViewer = new TreeViewer(this.parent);
  }

  /*
   * The method creates the context menu.
   */
  private void createContextMenu() {
    menuManager = new MenuManager();
    menuManager.setRemoveAllWhenShown(true);
    Menu treeContextMenu = menuManager.createContextMenu(
        this.treeViewer.getControl());
    this.treeViewer.getControl().setMenu(treeContextMenu);
    super.getSite().registerContextMenu(menuManager, this.treeViewer);
  }

}
